/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2011-2020 Rock Mao
* creator : Rock Mao
* created : 2011-5-2   22:29
* filename: LaborD3D11VertexBuffer.cpp
-----------------------------------------------------------------------------
*/
#include "stdafx.h"
#include "LaborD3D11VertexBuffer.h"
NAMESPACE_LABOR3D_BEGIN

//---------------------------------------------------------------------
CLD3D11VertexBuffer::CLD3D11VertexBuffer(size_t vertexSize, 
										 size_t numVertices, EHB_Usage usage, CLD3D11Device & device, 
										 bool useSystemMemory, bool useShadowBuffer)
										 : CLVertexBuffer(vertexSize, numVertices, usage, useSystemMemory, useShadowBuffer)
{
	// everything is done via internal generalisation
	mBufferImpl = new CLD3D11HardwareBuffer(eL_VERTEX_BUFFER, mSizeInBytes, mUsage, device, useSystemMemory, useShadowBuffer);
}

//---------------------------------------------------------------------
CLD3D11VertexBuffer::~CLD3D11VertexBuffer()
{
	delete mBufferImpl;
}

//---------------------------------------------------------------------
void* CLD3D11VertexBuffer::lock(size_t offset, size_t length, EHB_LockOptions options)
{
	return mBufferImpl->lock(offset, length, options);
}
//---------------------------------------------------------------------
void CLD3D11VertexBuffer::unlock(void)
{
	mBufferImpl->unlock();
}
//---------------------------------------------------------------------
void CLD3D11VertexBuffer::readData(size_t offset, size_t length, void* pDest)
{
	mBufferImpl->readData(offset, length, pDest);
}
//---------------------------------------------------------------------
void CLD3D11VertexBuffer::writeData(size_t offset, size_t length, const void* pSource,
									bool discardWholeBuffer)
{
	mBufferImpl->writeData(offset, length, pSource, discardWholeBuffer);
}
//---------------------------------------------------------------------
void CLD3D11VertexBuffer::copyData(CLHardwareBuffer& srcBuffer, size_t srcOffset, 
								   size_t dstOffset, size_t length, bool discardWholeBuffer)
{
	CLD3D11VertexBuffer& d3dBuf = static_cast<CLD3D11VertexBuffer&>(srcBuffer);

	mBufferImpl->copyData(*(d3dBuf.mBufferImpl), srcOffset, dstOffset, length, discardWholeBuffer);
}
//---------------------------------------------------------------------
bool CLD3D11VertexBuffer::isLocked(void) const
{
	return mBufferImpl->isLocked();
}
//---------------------------------------------------------------------
bool CLD3D11VertexBuffer::releaseIfDefaultPool(void)
{
	/*		if (mD3DPool == D3DPOOL_DEFAULT)
	{
	SAFE_RELEASE(mlpD3DBuffer);
	return true;
	}
	return false;
	*/
	return true;
}
//---------------------------------------------------------------------
bool CLD3D11VertexBuffer::recreateIfDefaultPool(CLD3D11Device & device)
{
	return true;
}
//---------------------------------------------------------------------
ID3D11Buffer * CLD3D11VertexBuffer::getD3DVertexBuffer( void ) const
{
	return mBufferImpl->getD3DBuffer();
}
//---------------------------------------------------------------------
NAMESPACE_LABOR3D_END